
package com.huizhan.web.controller;
 
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.data.domain.Sort.*;
import io.swagger.annotations.*;
import java.util.*;

import com.huizhan.web.view.*;
import com.huizhan.web.dao.*;
import com.huizhan.web.model.*;

/**
 * 用户日志api
 */
@Api(tags = "AccountLog",description = "用户日志")
@RestController
public class AccountLogController {
    
    @Autowired
    private AccountLogDao dao;
   
    /**
     * 获取用户日志集合
     * @return api结果
     */
    @ApiOperation(value = "获取用户日志集合")
    @RequestMapping(value =  "/api/AccountLog/",method = {RequestMethod.GET})
    public ApiResult<List<AccountLog>> Get(){
         ApiResult<List<AccountLog>> result=new ApiResult<List<AccountLog>>();
        try 
        {
            List<AccountLog> res = dao.findAll();
            result.setData(res);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 根据ID获取用户日志信息
     * @param id 用户日志ID
     * @return api结果
     */
    @ApiOperation(value = "根据ID获取用户日志信息")
    @RequestMapping(value =  "/api/AccountLog/{id}",method = {RequestMethod.GET})
    public ApiResult<AccountLog> Get(@PathVariable Long id){
        ApiResult<AccountLog> result=new ApiResult<AccountLog>();
        try
        {
            AccountLog model= dao.getOne(id);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 修改用户日志信息
     * @param id 用户日志ID
     * @param model 用户日志信息
     * @return api结果
     */
    @ApiOperation(value = "修改用户日志信息")
    @RequestMapping(value =  "/api/AccountLog/{id}",method = {RequestMethod.PUT})
    public ApiResult<AccountLog> Edit(@PathVariable Long id,@RequestBody AccountLog model){
        ApiResult<AccountLog> result=new ApiResult<AccountLog>();
        try
        {
            model.setAccountLogId(id);
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return  result;
    }

    /**
     * 查询账号日志信息
     * @param model 账号日志信息
     * @return api结果
     */
    @ApiOperation(value = "查询账号日志信息")
    @RequestMapping(value =  "/api/AccountLog/Search",method = {RequestMethod.POST})
    public ApiResult<List<AccountLog>> Search(@RequestBody PageProject model){
         ApiResult<List<AccountLog>> result=new ApiResult<List<AccountLog>>();
         
        try
        {    
            PageRequest pageable = PageRequest.of(model.getPageIndex(),model.getPageSize(),Direction.DESC,"account_log_Id") ;            
            Page<AccountLog> page = dao.findByWhere(model.getName(),model.getRemark(),model.getType(),model.getProjectId(),pageable);
            result.setData(page.getContent());
            result.setTotal(page.getTotalElements());
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }

    /**
     * 添加用户日志信息
     * @param model 用户日志信息
     * @return api结果
     */
    @ApiOperation(value = "添加用户日志信息")
    @RequestMapping(value =  "/api/AccountLog/",method = {RequestMethod.POST})
    public ApiResult<AccountLog> Add(@RequestBody AccountLog model){
         ApiResult<AccountLog> result=new ApiResult<AccountLog>();
        try
        {
            model.setCreateDate(new Date());
            dao.save(model);
            result.setData(model);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
    
    /**
     * 删除用户日志信息
     * @param id 用户日志ID
     * @return api结果
     */
    @ApiOperation(value = "删除用户日志信息")
    @RequestMapping(value =  "/api/AccountLog/{id}",method = {RequestMethod.DELETE})
    public ApiResult<Object> Delete(@PathVariable  Long id){
        ApiResult<Object> result=new ApiResult<Object>();
        try 
        {
            dao.deleteById(id);
        }catch(Exception e){
            result.setHasError(true);
            result.setMessage(e.getMessage());
        }
        return result;
    }
}

